# _*_ coding: utf-8 _*_
import requests
from lxml.etree import HTML
from .UserAgent import UserAgent
# https://www.xbiquge.la/81/81806/31818938.html

class NovelSpider(object):
    def __init__(self):
        self.__url = None
        self.__response = None


    @property
    def url(self) -> str:
        return self.__url


    @url.setter
    def url(self, val: str) -> None:
        self.__url = val


    def setHeaders(self) -> dict:
        return {
            "User-Agent": UserAgent.random()
        }


    def sendGet(self) -> None:
        '''发送GET请求'''
        response = requests.get(
            url=self.url,
            headers=self.setHeaders()
        )
        response.encoding = "utf-8"
        self.__response = response


    def parse(self) -> list:
        '''解析响应'''
        root = HTML(self.__response.text)
        return root.xpath('''//div[@id="content"]/text()''')


if __name__ == "__main__":
    pass